/*
 * MediaChooser.java
 *
 * 07/11/2009
 */
package kg.sound.player.ui;

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;

import kg.sound.player.Config;

/**
 * @author fernando
 */
public class MediaChooser extends JFileChooser {

	private static final String DEFAULT_DIR_KEY = "DEFAULT_DIR";

	public MediaChooser() {
		super(Config.getString(DEFAULT_DIR_KEY, System.getProperty("user.dir")));
		setFileSelectionMode(FILES_ONLY);
		setFileFilter(new FileFilter() {

			@Override
			public boolean accept(File f) {
				return f.isDirectory()
						|| f.getName().matches(".*.mp3|.*.wav|.*.mid");
			}

			@Override
			public String getDescription() {
				return "Media File (*.mp3, *.wav, *.mid)";
			}

		});
	}

	/** {@inheritDoc} */
	@Override
	public void approveSelection() {
		Config.setString(DEFAULT_DIR_KEY, getCurrentDirectory().getPath());
		super.approveSelection();
	}
}
